const express = require("express");
const shopRouter = express.Router();
const shopServer = require("../../server/shopServer");
const sendMsg = require("../reqSendResult");
const { addShopValidate, getShopValidate } = require("../validate/shopValidate");

// 添加商户
shopRouter.post(
  "/addShop",
  sendMsg.asyncHandler(async (req, res, next) => {
    // 验证参数
    await addShopValidate(req, res, next);
    return await shopServer.addShop(req.body);
  }, "添加商户成功")
);
// 获取商户列表
shopRouter.get(
  "/getShopList",
  sendMsg.asyncHandler(async (req, res) => {
    // 验证参数
    await getShopValidate(req);
    return await shopServer.getShop(req.query.id, req.query.page, req.query.limit, req.query.keyword);
  }, "获取商户成功")
);
// 获取商户详情
shopRouter.get(
  "/getShopDetail",
  sendMsg.asyncHandler(async (req, res) => {
    return await shopServer.getShopDetail(req.query.id);
  }, "获取商户详情成功")
);
// 更新商户信息
shopRouter.put(
  "/updateShop",
  sendMsg.asyncHandler(async (req, res, next) => {
    // 验证参数
    // await addShopValidate(req, res, next);
    await shopServer.updateShop(req.body.id, req.body);
  }, "数据更新成功")
);
// 删除商户
shopRouter.delete(
  "/deleteShop",
  sendMsg.asyncHandler(async (req, res, next) => {
    // 验证参数
    // await addShopValidate(req, res, next);
    await shopServer.deleteShop(req.query.id);
  }, "数据删除成功")
);

module.exports = shopRouter;